<?php
require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';

class AgentDao extends BaseDao {
	protected $_name;
	protected $joinAgentTotal;
	protected $joinCertificate;
	protected $joinAgentTradeLog;

	public function _setup(){
		$this->_name="agents";
		$this->joinAgentTotal="account_agent_totals";
		$this->joinCertificate="agent_certificates";
		$this->joinAgentTradeLog ="account_agent_trade_logs";
		parent::_setup();
	}

//	public function getAgentById($id){
//		$select=$this->db_r->select();
//		$select->from($this->_name,array('create_time as ct','*'));
//		$select->joinLeft($this->joinAgentTotal,
//		$this->_name . ".user_id=$this->joinAgentTotal.user_id",
//		array("balance","debt_total","debt_balance","usage_balance",
//		"freezed_balance","supplement_cnt","supplement_sum",
//		"supplement_last_time","order_cnt","order_sum","order_self_sale_sum",
//		"order_auto_recv_sum","order_campus_sum","order_last_time","order_last_type",
//		"order_dealing_cnt","order_dealing_sum","withdraw_cnt","withdraw_sum",
//		"withdraw_last_time","profit"));
//		$select->joinLeft($this->joinCertificate,
//		$this->_name . ".user_id=$this->joinCertificate.user_id and $this->joinCertificate.is_delete=0",
//		array("crt_num","file_path"));
//		$select->where($this->_name . '.id=?',$id);
//		$select->where($this->_name . '.is_delete=?',0);
//		$sql=$select->__toString();
//		return $this->db_r->fetchRow($sql);
//	}

	//	public function deleteCertificate($id){
	//		$db=$this->db_w;
	//		$set=array('is_delete'=>1);
	//		$where=$db->quoteInto('id=?',$id);
	//		$db->update($this->joinCertificate,$set,$where);
	//	}

	public function getAgentByTradeLogId($tradeLogId){
		$select=$this->db_r->select();
		$select->from($this->_name,array('*'));
		$select->joinLeft($this->joinAgentTradeLog,$this->_name . ".user_id=$this->joinAgentTradeLog.user_id",array("user_id"));
		$select->where($this->joinAgentTradeLog . '.id=?',$tradeLogId);
		$select->where($this->_name . '.is_delete=?',0);
		$sql=$select->__toString();
		return $this->db_r->fetchRow($sql);
	}
//	public function getCertificateByUseridAndTrcnum($userid,$num){//jason
//
//		$select=$this->db_r->select();
//		$select->from($this->joinCertificate,array('*'));
//		$select->where($this->joinCertificate . '.user_id=?',$userid);
//		$select->where($this->joinCertificate . '.crt_num=?',$num);
//		$select->where($this->joinCertificate . '.is_delete=?',0);
//		$sql=$select->__toString();
//		return $this->db_r->fetchRow($sql);
//	}
//	public function updateAgentByUserid($data,$userid){//jason
//
//		$where=$this->db_w->quoteInto('user_id=?',$userid);
//		$this->db_w->update($this->_name, $data, $where);
//
//	}
//	public function delAgentByUserid($userid){//jsaon
//
//		$set=array('is_delete'=>1);
//		$where=$this->db_w->quoteInto('user_id=?',$userid);
//		$this->db_w->update($this->_name,$set,$where);
//	}
//	public function getAgentByUserid($userid){//jason
//
//		$select=$this->db_r->select();
//		$select->from($this->_name);
//		$select->where($this->_name .'.user_id=?',$userid);
//		$select->where($this->_name . '.is_delete=?',0);
//		$sql=$select->__toString();
//		return $this->db_r->fetchRow($sql);
//	}
//	public function getAllAgentByUserid($userid){//jason
//
//		$select=$this->db_r->select();
//		$select->from($this->_name);
//		$select->where($this->_name .'.user_id=?',$userid);
//		$sql=$select->__toString();
//		return $this->db_r->fetchRow($sql);
//	}
}
?>